import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * @ CLassName GussNumber01
 * @ Author wang-haiyang1
 * @ Date 2022/2/22 19:53
 */

public class GussNumber01 {

    private static boolean flag = true;
    private static int times = 0;
    private static Scanner scanner;
    private static int num = (int) (1 + Math.random() * 99);

    public static void main(String[] args) {

        System.out.println("让我们来玩一个游戏吧，我心里想了一个数字（范围1-100），你来猜猜看。一共有七次机会哦~~");
        while (flag && times < 7) {
            System.out.print("告诉我你猜的数字吧(还有" + (7 - times) + "次机会)：");
            scanner = new Scanner(System.in);
            try {
                int i = scanner.nextInt();
                if (i == num) {
                    System.out.println("哎我滴妈呀，太神了吧？！这都猜对了，下次不会让你这么容易猜到！！！");
                    endTips();
                } else if (i - num > 0) {
                    System.out.println("数大了！");
                } else if (num - i > 0) {
                    System.out.println("数小了！");
                }
            } catch (InputMismatchException e) {
                System.out.println("只能输入数字奥家人！");
            }
            times++;
            if (times == 7) endTips();
        }
    }

    public static void endTips() {
        System.out.println("客官，再玩一次吗？(输入y继续)");
        char i1 =  scanner.next().charAt(0);
        if (i1 == 'y') {
            num = (int) (1 + Math.random() * 99);
            times = 0;
        } else {
            flag = false;
            System.out.println("游戏结束，撒由那拉...");
        }
    }

}
